import { login } from '@api/login'
  const state =  { // 状态
    token: '',
    userInfo: {}
  }
  const mutations = { // 计算属性
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_USERINFO: (state, userInfo) => {
      state.userInfo = userInfo
    },
  }
  const actions = { // 异步操作
    Login(context, data) {
      console.log('从login.vue传回来的数据', data)
      let params = {
        password: data.password.trim(),
        userName: data.username
      }
      return new Promise((resolve, reject) => {
        login(params).then(res => {
          context.commit('SET_TOKEN', `Bearer ${res.data.token}`)
          context.commit('SET_USERINFO', res.data)
          resolve(res.data)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
export default {
  state,
  mutations,
  actions
}
